package com.robb19y.rgbdscanner.core;

import java.util.ArrayList;

public class RGBDFilter {
	private int initPixelRow = 0;
	private int initPixelCol = 0;
	private int finalPixelRow = 640/2;
	private int finalPixelCol = 480/2;
	private int pixelStep = 1; 	
	private ColorFilter colorFilter;	
	private double maxDist = 999999999;
	
	public ArrayList<RGBDData> filter(RGBDData[][] data){
		ArrayList<RGBDData> dataList = new ArrayList<RGBDData>((finalPixelRow-initPixelRow)*(finalPixelCol-initPixelCol)/(pixelStep*pixelStep));
		RGBDData d;
		if(colorFilter == null){
			for(int i = initPixelRow; i < finalPixelRow; i = i + pixelStep){
				for(int j = initPixelCol; j < finalPixelCol; j = j + pixelStep){
					d = data[i][j];
					if(d.isValid() && d.getDepth() < maxDist){
						dataList.add(d);			
					}
				}
			}
		}else{
			for(int i = initPixelRow; i < finalPixelRow; i = i + pixelStep){
				for(int j = initPixelCol; j < finalPixelCol; j = j + pixelStep){
					d = data[i][j];
					if(d.isValid()&&d.getDepth() < maxDist && colorFilter.filter(d.getColor())){
						dataList.add(d);			
					}
				}
			}
		}	
		return dataList;
	
	}

	public int getInitPixelRow() {
		return initPixelRow;
	}

	public void setInitPixelRow(int initPixelRow) {
		this.initPixelRow = initPixelRow;
	}

	public int getInitPixelCol() {
		return initPixelCol;
	}

	public void setInitPixelCol(int initPixelCol) {
		this.initPixelCol = initPixelCol;
	}

	public int getFinalPixelRow() {
		return finalPixelRow;
	}

	public void setFinalPixelRow(int finalPixelRow) {
		this.finalPixelRow = finalPixelRow;
	}

	public int getFinalPixelCol() {
		return finalPixelCol;
	}

	public void setFinalPixelCol(int finalPixelCol) {
		this.finalPixelCol = finalPixelCol;
	}

	public int getPixelStep() {
		return pixelStep;
	}

	public void setPixelStep(int pixelStep) {
		this.pixelStep = pixelStep;
	}

	public ColorFilter getColorFilter() {
		return colorFilter;
	}

	public void setColorFilter(ColorFilter colorFilter) {
		this.colorFilter = colorFilter;
	}

	public double getMaxDist() {
		return maxDist;
	}

	public void setMaxDist(double maxDist) {
		this.maxDist = maxDist;
	}
	
	

}
